<template>
  <!-- 转正的表单 -->
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>转正信息</span>
      </div>
      <div class="body">
        <el-form ref="form" :model="form" label-width="180px">
          <el-col :span="12">
            <el-form-item label="姓名：">
              {{ form.name }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工号：">
              {{ form._id }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件号码：">
              {{ form.sid }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号：">
              {{ form.phone }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工作性质：">
              {{ form.nature }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="人员状态：">
              {{ form.state }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="部门：">
              <el-input placeholder="部门" v-model="form.stationId.name">
                <i slot="suffix" class="el-input__icon el-icon-date"></i>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="岗位：">
              <el-input placeholder="岗位" v-model="form.organId.name">
                <i slot="suffix" class="el-input__icon el-icon-date"></i>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入职日期：">
              {{ form.entry | Day }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="试用期：">
              {{ form.try }}
            </el-form-item>
          </el-col>

          <el-form-item label="转正日期：">
            <el-col :span="12">
              <el-date-picker
                v-model="form.formalTime"
                type="date"
                placeholder="选择日期"
                style="width: 83%"
              >
              </el-date-picker>
            </el-col>
          </el-form-item>
           <el-form-item label="备注：">
    <el-input type="textarea" v-model="form.ps" placeholder="请输入"></el-input>
  </el-form-item>
          <el-form-item>
            <el-button @click="go()">返回</el-button>
            <el-button type="primary" @click="onSubmit">转正</el-button>
            <el-button @click="go()">取消</el-button>
            
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "VueSalarysysConverted",

  data() {
    return {
      form: {
        name: "",
        // 组织 部门
        stationId: "",
        // 岗位
        organId: "",
        phone: "",
        // 工号———_id
        _id: "",
        // 证件号
        sid: "",
        // 工作性质 ———— 全职 临时
        nature: "",
        // 入职时间
        entry: "",
        // 状态————正式 试用 待离职 已离职
        state: "",
        // 转正时间
        formalTime: "",
        // 试用期
        try: "",
        // 备注
        ps:'',
      },
    };
  },

  mounted() {
    this.getData(this.$route.query.id);
  },

  methods: {
    async getData(id) {
      let { data } = await this.$axios.get("/organ/getConverted?id=" + id);

      this.form = data.data[0];
      console.log(this.form);
    },
    async onSubmit() {
      console.log(this.form);
      let formal =  (this.form.formalTime)
      let today = Date.parse(Date())
      if(today>formal){
        // alert('可以转正')
        let {data} = await this.$axios.get('/organ/setOK?id='+this.form._id)
        if(data.code === 200){
          this.$router.push('/home/staff')
        }
        console.log(data);
      }else{
        this.$notify.error({
          title: '错误',
          message: '给员工还在实习期，不可转正'
        });
      }
    },
    go(){
      window.history.go(-1)
    }
  },
};
</script>

<style lang="scss" scoped>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 100%;
}
</style>